package com.sufun.test;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.widget.ListView;

import com.ab.http.AbRequestParams;
import com.ab.view.pullview.AbPullToRefreshView;
import com.sufun.activities.SFBaseAct;
import com.sufun.adapters.ImageAdapter;
import com.sufun.adapters.SFBaseAdapterConfig;
import com.sufun.base.SFConfig;
import com.sufun.fetches.IFetch;
import com.sufun.fetches.ImageModelFetches;
import com.sufun.models.DataResultModel;
import com.sufun.models.ImageModel;
import com.sufun.sfdroid.R;

public class SFHttpTestAct extends SFBaseAct {

	AbPullToRefreshView pullrefresh;
	ListView  listView;
	ImageModelFetches fetches=new ImageModelFetches(new AbRequestParams(), "");
	ImageAdapter adapter;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setAbContentView(R.layout.sf_data_refresh_test_act);
		//initHttpRequest();
		initListViewData();
	}
	
	void initListViewData()
	{
		pullrefresh=(AbPullToRefreshView)findViewById(R.id.mPullRefreshView);
		listView=(ListView)findViewById(R.id.mListView);
		fetches=new ImageModelFetches(new AbRequestParams(), "");
		adapter=new ImageAdapter();
		SFBaseAdapterConfig config=new SFBaseAdapterConfig<ImageModel>();
		config.baseFetch=fetches;
		config.mContext=this;
		config.mDatas=new ArrayList<ImageModel>();
		config.mListView=listView;
		config.mRefreshView=pullrefresh;
		adapter.initAdapterDatas(config);
		fetches.doPost();		
	}
	/**
	 * 测试http请求
	 */
	void initHttpRequest()
	{
		ImageModelFetches fetches=new ImageModelFetches(new AbRequestParams(), "");
		fetches.mFetchAnsyCallback=new IFetch<ImageModel>() {
			
			@Override
			public void OnSuccess(List<ImageModel> datas) {
				// TODO Auto-generated method stub
				for (int i = 0; i < datas.size(); i++) {
					SFConfig.D(datas.get(i).content);
					SFConfig.D(datas.get(i).image_url);
				}
			}
			
			@Override
			public void OnReFresh() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void OnPrepare() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void OnLoading(int data) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void OnLoadMore() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void OnFinish() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void OnFail(DataResultModel result) {
				// TODO Auto-generated method stub
				
			}
		};
		fetches.doPost();
	}
}
